﻿using Flurl.Http;
using HandyControl.Controls;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using wms_wpf.Dto;
using wms_wpf.InPut;

namespace wms_wpf.Apiservice
{
    public class ViewService : IViewService
    {
        string config = Environment.GetEnvironmentVariable("wms-config", EnvironmentVariableTarget.Machine);
        public async Task<Tuple<List<View_MaterialsDto>, long?, long?>> GetList_View_Materials(InPut_ViewService Input)
        {
            try
            {
                var url = $"http://{config}/api/ViewService/GetList_View_Materials";
                var data = Input;
                string result = await url.PostJsonAsync(data).ReceiveString();
                ApiResponsePage Response = JsonConvert.DeserializeObject<ApiResponsePage>(result);
                if (Response.State)
                {
                    List<View_MaterialsDto> res = JsonConvert.DeserializeObject<List<View_MaterialsDto>>(Response.Dto.ToString());
                    return Tuple.Create(res, Response.Count, Response.PageCount);
                }
                else
                {
                    Growl.Info(Response.Msg, "msg");
                    return null;
                }


            }
            catch (Exception ex)
            {
                Growl.Error("接口调用失败", "msg");
                LognetHelper.WriteLog("GetList_View_Materials", ex);
                return null;
            }
        }
    }
}
